<?php
if( !defined('IN_INDEX') )
{
	printError("ACCESS DENIED", "This page is hidden.");
	exit;
}
// --------------------------------------------------------
// The class user contains methods for working 
// with users
// --------------------------------------------------------
class User
{
	var $id = 0;
	var $rank = 0;
	var $email = "N/A";
	var $password = "N/A";
	var $birthday = "00-00-0000";
	var $lang = "N/A";
	var $country = "N/A";
	var $firstname = "N/A";
	var $lastname = "N/A";
	var $date_format = "N/A";
	var $date_format_long = "N/A";
	var $timezone = 0;
	var $joined = 0;
	var $lastlogin = 0;
	var $posts = 0;
	var $status = "N/A";
	var $avatarPath;
	var $gender = "N/A";
	var $weight_metric = "N/A";
	var $bodyweight = 0;
	var $place = "N/A";
	var $category = "N/A";
	var $blog_privacy = "N/A";
	var $blogs_per_page = "N/A";
	var $pm_per_page = "N/A";
	var $comments_per_page = "N/A";
	var $msg_from_comments = 0;
	var $show_blog_comments = 0;
	var $sort_comments = "N/A";
	var $sort_kg_reps = 0;
	var $show_bw = 0;
	var $show_training_in_blog = 0;
	var $show_weightchange = 0;
	var $show_pb = 0;
	var $activate_rpe = 0;
	var $about = "N/A";
	var $user_follow_list = "";
	var $user_get_email_notify = 0;
	var $user_get_email_notify_pm = 0;
	
	function User($cmd, $input)
	{
		global $db;
		
		if($cmd == 'id')
		{
			$sql = "SELECT * FROM " . USERS_TABLE . " ".
			"WHERE user_id='" . $input . "'";
		}
		else if($cmd == 'email')
		{
			$sql = "SELECT * FROM " . USERS_TABLE . " ".
			"WHERE user_email='" . $input . "'";
		}
		else
		{
			return false;
		}
		
		if( !($result = $db->sql_query($sql)) )
		{
			printError("SQL ERROR", mysql_error($sql));
		}
		if( $row = $db->sql_fetchrow($result) )
		{
			$this->id = $row['user_id'];
			$this->rank = $row['user_rank'];
			$this->email = $row['user_email'];
			$this->birthday = $row['user_birthday'];
			$this->lang = $row['user_lang'];
			$this->country = $row['user_country'];
			$this->firstname = $row['user_firstname'];
			$this->lastname = $row['user_lastname'];
			$this->password = $row['user_password'];
			$this->date_format = $row['user_dateformat'];
			$this->date_format_long = $row['user_dateformat_long'];
			$this->timezone = $row['user_timezone'];
			$this->joined = $row['user_joined'];
			$this->lastlogin = $row['user_lastlogin'];
			$this->posts = $row['user_posts'];
			$this->status = $row['user_status'];
			$this->avatarPath = $row['user_avatarPath'];
			$this->gender = $row['user_gender'];
			$this->weight_metric = $row['user_weight_metric'];
			$this->bodyweight = $row['user_bodyweight'];
			$this->place = $row['user_place'];
			$this->category = $row['user_category'];
			$this->blog_privacy = $row['user_blog_privacy'];
			$this->blogs_per_page = $row['user_blogs_per_page'];
			$this->pm_per_page = $row['user_pm_per_page'];
			$this->comments_per_page = $row['user_comments_per_page'];
			$this->msg_from_comments = $row['user_msg_from_comments'];
			$this->show_blog_comments = $row['user_show_blog_comments'];
			$this->sort_comments = $row['user_sort_comments'];
			$this->sort_kg_reps = $row['user_sort_kg_reps'];
			$this->show_bw = $row['user_show_bw'];
			$this->show_training_in_blog = $row['user_show_training_in_blog'];
			$this->show_weightchange = $row['user_show_weightchange'];
			$this->show_pb = $row['user_show_pb'];
			$this->activate_rpe = $row['user_activate_rpe'];
			$this->about = $row['user_about'];
			$this->user_follow_list = $row['user_follow_list'];
			$this->user_get_email_notify = $row['user_get_email_notify'];
			$this->user_get_email_notify_pm = $row['user_get_email_notify_pm'];
			return true;
		}
		return false;
	}
	
	function setRank($input){ $this->rank=$input; }
	function setEmail($input){ $this->email=$input; }
	function setPassword($input){ $this->password=$input; }
	function setBirthday($input){ $this->birthday=$input; }
	function setLang($input){ $this->lang=$input; }
	function setCountry($input){ $this->country=$input; }
	function setFirstname($input){ $this->firstname=$input; }
	function setLastname($input){ $this->lastname=$input; }
	function setDateFormat($input){ $this->date_format=$input; }
	function setDateFormatLong($input){ $this->date_format_long=$input; }
	function setTimezone($input){ $this->timezone=$input; }
	function setLastlogin($input){ $this->lastlogin=$input; }
	function addPosts(){ $this->posts+=1; }
	function setStatus($input){ $this->status=$input; }
	function setAvatarpath($input){ $this->avatarPath=$input; }
	function setGender($input) { $this->gender=$input; }
	function setWeight_metric($input){ $this->weight_metric=$input; }
	function setBodyweight($input){ $this->bodyweight=$input; }
	function setPlace($input){ $this->place=$input; }
	function setCategory($input){ $this->category=$input; }
	function setBlogPrivacy($input) { $this->blog_privacy=$input; }
	function setBlogsPerPage($input) { $this->blogs_per_page=$input; }
	function setPmPerPage($input) { $this->pm_per_page=$input; }
	function setCommentsPerPage($input) { $this->comments_per_page=$input; }
	function setMsgFromComments($input) { $this->msg_from_comments=$input; }
	function setShowBlogComments($input) { $this->show_blog_comments=$input; }
	function setSortComments($input) { $this->sort_comments=$input; }
	function setSortKgReps($input) { $this->sort_kg_reps=$input; }
	function setShowBw($input) { $this->show_bw=$input; }
	function setShowTrainingInBlog($input) { $this->show_training_in_blog=$input; }
	function setShowWeightchange($input) { $this->show_weightchange=$input; }
	function setShowPb($input) { $this->show_pb=$input; }
	function setActivateRpe($input) { $this->activate_rpe=$input; }
	function setAbout($input) { $this->about=$input; }
	function setUserFollowList($input){ $this->user_follow_list = $input; }
	function setUserGetEmailNotify($input){ $this->user_get_email_notify = $input;}
	function setUserGetEmailNotify_PM($input){ $this->user_get_email_notify_pm = $input;}
	
	function getId(){ return $this->id; }
	function getRank(){ return $this->rank; }
	function getEmail(){ return $this->email; }
	function getBirthday(){ return $this->birthday; }
	function getLastlogin(){ return $this->lastlogin; }
	function getLang(){ return $this->lang; }
	function getCountry(){ return $this->country; }
	function getFirstname(){ return $this->firstname; }
	function getLastname(){ return $this->lastname; }
	function getDateFormat(){ return $this->date_format; }
	function getDateFormatLong(){ return $this->date_format_long; }
	function getTimezone(){ return $this->timezone; }
	function getJoined(){ return $this->joined; }
	function getPosts(){ return $this->posts; }
	function getStatus(){ return $this->status; }
	function getAvatarpath(){ return $this->avatarPath; }
	function getGender(){ return $this->gender; }
	function getWeight_metric(){ return $this->weight_metric; }
	function getBodyweight(){ return $this->bodyweight; }
	function getPlace(){ return $this->place; }
	function getCategory(){ return $this->category; }
	function getBlogPrivacy() { return $this->blog_privacy; }
	function getBlogsPerPage() { return $this->blogs_per_page; }
	function getPmPerPage() { return $this->pm_per_page; }
	function getCommentsPerPage() { return $this->comments_per_page; }
	function getMsgFromComments() { return $this->msg_from_comments; }
	function getShowBlogComments() { return $this->show_blog_comments; }
	function getSortComments() { return $this->sort_comments; }
	function getSortKgReps() { return $this->sort_kg_reps; }
	function getShowBw() { return $this->show_bw; }
	function getShowTrainingInBlog() { return $this->show_training_in_blog; }
	function getShowWeightchange() { return $this->show_weightchange; }
	function getShowPb() { return $this->show_pb; }
	function getActivateRpe() { return $this->activate_rpe; }
	function getAbout() { return $this->about; }
	function getUserFollowList(){ return $this->user_follow_list; }
	function getUserEmailNotify(){ return $this->user_get_email_notify; }
	function getUserEmailNotify_PM(){ return $this->user_get_email_notify_pm; }
	
	function checkPassword($string)
	{
		if($string == $this->password)
		{
			return true;
		}
		return false;
	}
	
	function update()
	{
		global $db;
		$setPassword = "";
		if($this->password != "")
		{
			$setPassword = " user_password='" . $this->password . "', ";
		}
		
		$sql = "UPDATE " . USERS_TABLE . " 
		SET user_rank='" . $this->rank . "',
		user_email='" . $this->email . "', " .
		$setPassword . "
		user_birthday='" . $this->birthday . "',
		user_lang='" . $this->lang . "',
		user_country='" . $this->country . "',
		user_firstname='" . $this->firstname . "',
		user_lastname='" . $this->lastname . "',
		user_dateformat='" . $this->date_format . "',
		user_dateformat_long='" . $this->date_format_long . "',
		user_timezone='" . $this->timezone . "',
		user_joined='" . $this->joined . "',
		user_lastlogin='" . $this->lastlogin . "',
		user_posts='" . $this->posts . "',
		user_status='" . $this->status . "',
		user_weight_metric='" . $this->weight_metric . "',
		user_bodyweight='" . $this->bodyweight . "',
		user_place='" . $this->place . "',
		user_category='" . $this->category . "',
		user_gender='" . $this->gender . "',
		user_avatarPath='" . $this->avatarPath . "',
		user_blog_privacy='" . $this->blog_privacy . "',
		user_blogs_per_page='" . $this->blogs_per_page . "',
		user_pm_per_page='" . $this->pm_per_page . "',
		user_comments_per_page='" . $this->comments_per_page . "',
		user_msg_from_comments='" . $this->msg_from_comments . "',
		user_show_blog_comments='" . $this->show_blog_comments . "',
		user_sort_comments='" . $this->sort_comments . "',
		user_sort_kg_reps='" . $this->sort_kg_reps . "',
		user_show_bw='" . $this->show_bw . "',
		user_show_training_in_blog='" . $this->show_training_in_blog . "',
		user_show_weightchange='" . $this->show_weightchange . "',
		user_show_pb='" . $this->show_pb . "',
		user_activate_rpe='" . $this->activate_rpe . "',
		user_about='" . $this->about . "',
		user_follow_list ='".$this->user_follow_list."',
		user_get_email_notify ='".$this->user_get_email_notify."',
		user_get_email_notify_pm ='".$this->user_get_email_notify_pm."'
		WHERE user_id='" . $this->id . "'";

		if( !($result = $db->sql_query($sql)) )
		{
			printError("SQL ERROR", mysql_error($sql));
		}
		else
		{
			return true;
		}
		return false;
	}
}
?>